/*
 * Copyright 2002-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ouwa.lms.client.support.async;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;

public class ErrorDialogBox extends DialogBox {
	public ErrorDialogBox(Throwable ex) {
		super(false,true);
		
		setText("Oops! An error has occurred.");
		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.setSpacing(10);
		mainPanel.add(new Label(ex.getMessage()));
		DisclosurePanel panel = new DisclosurePanel("More details...");
		
		// Show the exception stack trace
		VerticalPanel stackTracePanel = new VerticalPanel();
		for(StackTraceElement ste : ex.getStackTrace()) {
			stackTracePanel.add(new Label(ste.toString()));
		}
		
		panel.setContent(stackTracePanel);
		mainPanel.add(panel);
		Button closeButton = new Button("Close");
		closeButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				hide();
			}
		});
		mainPanel.add(closeButton);
		mainPanel.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_CENTER);
		
		setWidget(mainPanel);
		center();
	}
}
